package com.wu.client.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wu.client.constant.RedisKeyConstant;

import com.wu.client.service.FollowersService;
import com.wu.client.vo.req.user.UserFollowReq;
import com.wu.mysql.entiy.FollowersDO;
import com.wu.mysql.mapper.FollowersMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class FollowersServiceImpl extends ServiceImpl<FollowersMapper, FollowersDO> implements FollowersService {

    private final StringRedisTemplate stringRedisTemplate;
    @Override
    public void add(UserFollowReq userFollowReq) {
        Long userId = userFollowReq.getUserId();
        Long followedId = userFollowReq.getFollowedId();
        Integer fansType = userFollowReq.getFansType();
        String fansRedisKey = RedisKeyConstant.getFansRedisKey(fansType, userId);
        stringRedisTemplate.opsForSet().add(fansRedisKey,followedId.toString());
    }

    @Override
    public void delete(Long userId, Long followedId, Integer fansType) {
        String fansRedisKey = RedisKeyConstant.getFansRedisKey(fansType, userId);
        stringRedisTemplate.opsForSet().remove(fansRedisKey,followedId.toString());
    }
}
